import { _decorator, Component, director, Node, Sprite, SpriteFrame } from 'cc';
import { LoadingManager } from './LoadingManager';
const { ccclass, property } = _decorator;

@ccclass('HomeManager')
export class HomeManager extends Component {

    @property(Node)
    private sanNode:Node;

    @property(Node)
    private dengNode:Node;

    @property(SpriteFrame)
    private san1:SpriteFrame;

    @property(SpriteFrame)
    private san2:SpriteFrame;

    @property(SpriteFrame)
    private deng1:SpriteFrame;

    @property(SpriteFrame)
    private deng2:SpriteFrame;

    @property(Node)
    private beginNode:Node;

    start() {

        //this.node.getChildByName("bg").getComponent(Sprite).spriteFrame = LoadingManager.bigFrames.get("home_bg");

        this.schedule(() => {
            const sprite = this.sanNode.getComponent(Sprite);
            if (sprite.spriteFrame.name == 'san1') {
                sprite.spriteFrame = this.san2;
            } else {
                sprite.spriteFrame = this.san1;
            }

        }, 0.4, 20000, 0.6);

        this.schedule(() => {

            const sprite = this.dengNode.getComponent(Sprite);
            if (sprite.spriteFrame.name == 'deng1') {
                sprite.spriteFrame = this.deng2;
            } else {
                sprite.spriteFrame = this.deng1;
            }
        }, 0.6, 10000, 0.3);


        this.beginNode.on(Node.EventType.TOUCH_END, () => {
            director.loadScene("game");
        });
    }

    update(deltaTime: number) {
        
    }
}

